﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_Province.cs
* 创建标识：曾乃强 15158756652 2011-04-19 09:04:41
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_Province*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_Province
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        /// <summary>
        /// 查看单个
        /// </summary>
        public Model.CNVP_Province LoadByCode(string Code)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[Name],[RangeName] from " + Prefix + "Province");
            sql.Append(" where [Code] = @Code");
            SqlParameter[] pra = {
                                 new SqlParameter("@Code",Code)
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_Province cnvp_province = new Model.CNVP_Province();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_province.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                cnvp_province.Name = dr["Name"] is DBNull ? String.Empty : (string)dr["Name"];
                cnvp_province.RangeName = dr["RangeName"] is DBNull ? String.Empty : (string)dr["RangeName"];
            }
             return cnvp_province;
        }
        /// <summary>
        /// 查看全部
        /// </summary>
        public List<Model.CNVP_Province> LoadAll(string sqlWhere)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[Code],[Name],[RangeName] from " + Prefix + "Province");
            if (sqlWhere.Trim() != "")
            {
                sql.Append(" where " + sqlWhere);
            }
            DataTable DT = DbHelper.ExecuteTable(sql.ToString());
            List<Model.CNVP_Province> list=new List<Model.CNVP_Province>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_Province cnvp_province = new Model.CNVP_Province();
                    cnvp_province.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_province.Code = dr["Code"] is DBNull ? String.Empty : (string)dr["Code"];
                    cnvp_province.Name = dr["Name"] is DBNull ? String.Empty : (string)dr["Name"];
                    cnvp_province.RangeName = dr["RangeName"] is DBNull ? String.Empty : (string)dr["RangeName"];
                    list.Add(cnvp_province);
                }
            }
            return list;
        }


        #endregion
    }
}

